package com.example.recycleview;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
    private List<Person> PersonList;

    public RecyclerAdapter(List<Person> PersonList)
    {
        this.PersonList = PersonList;
    }

    @NonNull
    @Override
    public RecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerAdapter.ViewHolder holder, int position) {
        holder.id.setText(String.valueOf(PersonList.get(position).getId()));
        holder.name.setText(PersonList.get(position).getName());
        holder.action.setText(PersonList.get(position).getAction());
    }

    @Override
    public int getItemCount() {
        return PersonList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView id;
        TextView name;
        TextView action;

        public ViewHolder(@NonNull View itemView)
        {
            super(itemView);
            this.id= itemView.findViewById(R.id.tv_id);
            this.name= itemView.findViewById(R.id.tv_name);
            this.action= itemView.findViewById(R.id.tv_action);
        }

    }
}